package com.itheima.reflect;

import com.itheima.domain.Student;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;

/*
各种获取构造方法
 */
public class Demo02 {


    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class<Student> clazz = Student.class;
        Constructor<?>[] constructors = clazz.getConstructors();
        System.out.println(Arrays.toString(constructors));

        Constructor<?>[] declaredConstructors = clazz.getDeclaredConstructors();
        System.out.println(Arrays.toString(declaredConstructors));

        Constructor<Student> constructor = clazz.getConstructor();

        System.out.println(constructor);
        Student student = constructor.newInstance();
        System.out.println(student);

        Constructor<Student> declaredConstructor = clazz.getDeclaredConstructor(String.class);
        System.out.println(declaredConstructor);
        //String.class  ""
        declaredConstructor.setAccessible(true);
        Student student1 = declaredConstructor.newInstance("吴亦凡");

        System.out.println(student1);

        Constructor<Student> allFieldConstructor = clazz.getDeclaredConstructor(int.class, String.class);
        Student student2 = allFieldConstructor.newInstance(31, "吴亦凡");
        System.out.println(student2);


    }
}
